package com.tm.config;


import com.tm.mapper.PayMemberMapper;
import com.tm.service.PayMemberService;
import com.tm.util.EmailNotofication;
import com.tm.util.SendSmsutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import tm.pojo.ImageDynamic;
import tm.pojo.RechargePojo;
import tm.pojo.UserPojo;
import tm.result.Result;

import java.util.Date;
import java.util.List;

//@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {


    @Autowired
    private PayMemberMapper payMemberMapper;


    //3.添加定时任务
    @Scheduled(cron = "* * 0/1 * * ?")
    public Result queryMemberOut(){
        long l = new Date().getTime() / 1000;
        //查询数据库得到所有三天内到期的会员
        List<RechargePojo>list=payMemberMapper.queryMemberOut(l);
        for (int i = 0; i < list.size(); i++) {
            RechargePojo rechargePojo = list.get(i);
            Integer userId = rechargePojo.getUserId();
            UserPojo userPojo= payMemberMapper.queryUserByid(userId);
            String phonenumber = userPojo.getPhonenumber();
            String s = SendSmsutil.loginsendSms(phonenumber);
        }
        return Result.SUCCESS();

    }
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)

    private List<ImageDynamic>queryByImage(ImageDynamic imageDynamic){
        if (imageDynamic.getDynamicImgPortraitRflag()==2){
            Integer dynamicImgPortraitRflag = imageDynamic.getDynamicImgPortraitRflag();
            EmailNotofication.senEmail("大概有"+dynamicImgPortraitRflag+"张未审核的照片，请您进行审核，You should be love you job");
        }
        return null;
    }
}
